Skip to content

Convert file-level rustfmt skip to fn level skips #3809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 13, 2025

Conversation

joostjager
Copy link
Contributor

@joostjager joostjager commented May 29, 2025

Extend the approach proposed in #3767 to the full repository. The change set is automatically generated using a script. The script omits skip directives when they would not impact formatting (code already rustfmt-compliant).

I've fixed various problems with the script, and it may be that there are a few edge cases left that should have had a skip directive. There could also be a few redundant ones. I think we can live with that.

Omitted are files that are formatted in in-flight rustfmt PRs: #3783, #3725 , #3338 and #3337

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented May 29, 2025

👋 Thanks for assigning @TheBlueMatt as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@joostjager joostjager force-pushed the rustfmt-skip-all branch 2 times, most recently from a88062e to 16025f2 Compare May 29, 2025 14:26
@joostjager
Copy link
Contributor Author

As discussed in sync meet, I will try to extend the script to ignore rustfmt changes that only affect the function signature.

@joostjager
Copy link
Contributor Author

Pushed fix up commit to ignore sig changes. Modest reduction in skips, with a few edge cases.

Copy link

codecov bot commented Jun 2, 2025

Codecov Report

Attention: Patch coverage is 99.01153% with 6 lines in your changes missing coverage. Please review.

Project coverage is 89.91%. Comparing base (e797180) to head (a38db49).

Files with missing lines Patch % Lines
lightning/src/chain/channelmonitor.rs 91.17% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3809      +/-   ##
==========================================
+ Coverage   89.87%   89.91%   +0.03%     
==========================================
  Files         162      162              
  Lines      130214   130684     +470     
  Branches   130214   130684     +470     
==========================================
+ Hits       117034   117508     +474     
+ Misses      10486    10484       -2     
+ Partials     2694     2692       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this in draft? This needs a rebase by now, too.

@@ -1,48 +1,47 @@
#![cfg_attr(rustfmt, rustfmt_skip)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was put here deliberately as we opted against running rustfmt on autogenerated files. We need to fix it either way, likely just revert it to include the skip.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, didn't know it was auto-generated. Removed the commit that formats this file.

@joostjager
Copy link
Contributor Author

It's in draft because I want to see #3767 merged first. Don't want to spend time on rebase if we don't go this way.

@joostjager
Copy link
Contributor Author

#3767 seems a positive change. New code being added in PRs (for example async payments) is now automatically formatted and not creating more formatting debt. No bad rebase conflicts that I've heard of either.

Enough to go ahead and re-run the script on the latest main.

Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from what I've seen so far.

Mind including the same changes for the remaining files in chain,ln, and routing, too?

@joostjager
Copy link
Contributor Author

LGTM from what I've seen so far.

Mind including the same changes for the remaining files in chain,ln, and routing, too?

Intentionally left these out because there are fmt prs in flight for those files. Links in pr desc

@tnull
Copy link
Contributor

tnull commented Jun 11, 2025

Intentionally left these out because there are fmt prs in flight for those files. Links in pr desc

Ah, right. The remaining ones in routing never went far, so now closed them for now. Please include routing here.

@joostjager
Copy link
Contributor Author

Re-added routing files.

@joostjager joostjager marked this pull request as ready for review June 11, 2025 12:53
@joostjager joostjager requested a review from tnull June 11, 2025 15:04
@TheBlueMatt
Copy link
Collaborator

I admit I'm kinda meh oh doing this for everything. There's a handful of files left that are pretty small and can be easily formatted (at least once trampoline PRs land for chain and the router module PRs get picked back up), and for tests I understood the plan to be "move forward, get there soon" (I know, I know, I plan on finishing #3783 this week), so applying skips to everything in tests (which generally aren't regularly touched) just to format them soon seems kinda weird?

For large files that we want to format iteratively (channelmanager, channel, maybe some of chain though many of those files aren't that large, just very actively being edited), this approach makes a ton of sense, for every file I'm not sure that we want to always format iteratively?

@joostjager
Copy link
Contributor Author

I admit I'm kinda meh oh doing this for everything. There's a handful of files left that are pretty small and can be easily formatted (at least once trampoline PRs land for chain and the router module PRs get picked back up), and for tests I understood the plan to be "move forward, get there soon" (I know, I know, I plan on finishing #3783 this week), so applying skips to everything in tests (which generally aren't regularly touched) just to format them soon seems kinda weird?

I see what you mean. Applying skips now and removing them "soon" feels unnecessary. The way I see it though is that "soon" may be quite a bit further out than we'd like. Trampoline for example may take a while. Adding the skips doesn't hurt, they can easily be removed again if someone feels inclined to format a full file, and they add flexibility for devs to selectively format for whatever reason.

For large files that we want to format iteratively (channelmanager, channel, maybe some of chain though many of those files aren't that large, just very actively being edited), this approach makes a ton of sense, for every file I'm not sure that we want to always format iteratively?

I needed to rebase this PR anyway, and while I did I left out the test files. If you feel it is still too much, maybe you can list the exact files that are definitely good for the incremental approach?

@joostjager
Copy link
Contributor Author

joostjager commented Jun 12, 2025

Also not sure at all that doing the tests all in one with mass edits is ideal: #3783 (review)

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the file list here makes sense. I thought there were substantially more changes to onion_payment.rs for trampoline to come but @valentinewallace tells me they're more in outbound_payment.rs which has more active development and thus higher cost to delaying pushing the format skips down in it.

monitor.provide_secret(281474976710655, secrets.last().unwrap().clone()).unwrap();
test_secrets!();

secrets.push([0; 32]);
secrets.last_mut().unwrap()[0..32].clone_from_slice(&<Vec<u8>>::from_hex("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
secrets.last_mut().unwrap()[0..32].clone_from_slice(
&<Vec<u8>>::from_hex(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to go ahead and break the hex constants out to give them names?

Copy link
Contributor Author

@joostjager joostjager Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. All gave them the same hex name though...

@joostjager joostjager force-pushed the rustfmt-skip-all branch 3 times, most recently from 7d69403 to 516fdb3 Compare June 12, 2025 18:42
@joostjager
Copy link
Contributor Author

Removed redundant skips. Didn't do the optional improvements (format short fns), because it is probably easiest to keep this big PR "pure" and do the rest in follow ups.

@joostjager
Copy link
Contributor Author

Didn't squash the redundant skip removal commit, in case I need to re-run the script and re-apply the edge case fixes.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

11 files changed, 1984 insertions(+), 668 deletions(-)

Holy diff-size batman!

@joostjager joostjager merged commit 3e9e6a3 into lightningdevkit:main Jun 13, 2025
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants